﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nop.Core.Data;
using Nop.Core.Domain.Common;
using Nop.Core.Events;
using Nop.Core.Caching;

namespace Nop.Services.Common
{
    public class MenuService : IMenuService
    {

        private const string CATEGORIES_BY_ID_KEY = "Nop.Menu.id-{0}";
        private const string CATEGORIES_BY_PARENT_CATEGORY_ID_KEY = "Nop.Menu.byparent-{0}-{1}";

        #region Fields

        private readonly IRepository<Menu> _menuRepository;
        private readonly IEventPublisher _eventPublisher;
        private readonly ICacheManager _cacheManager;
        #endregion

          #region Ctor

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="cacheManager">Cache manager</param>
        /// <param name="categoryRepository">Category repository</param>
        /// <param name="productCategoryRepository">ProductCategory repository</param>
        /// <param name="productRepository">Product repository</param>
        /// <param name="eventPublisher">Event publisher</param>
        public MenuService(ICacheManager cacheManager,
            IEventPublisher eventPublisher, IRepository<Menu> menuRepository)
        {
            this._cacheManager = cacheManager;
            this._eventPublisher = eventPublisher;
            this._menuRepository = menuRepository;
        }

        #endregion


        #region 自定义
        /// <summary>
        /// 查询菜单根据显示顺序排序
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable<Menu> GetAllMenu()
        {
            var query = from p in _menuRepository.Table
                        where p.State
                        orderby p.OrderDisplay ascending
                        select p;
            return query;
        }

        #endregion
    }
}
